package com.hdsx.restful.glzt.structure.fwq.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.esri.arcgis.geometry.IGeometry;
import com.hdsx.ao.base.BaseOpearte;
import com.hdsx.restful.glzt.roadline.lxxx.bean.Znode;
import com.hdsx.restful.glzt.structure.fwq.bean.Fwq;
import com.hdsx.restful.glzt.structure.fwq.mapper.FwqMapper;
import com.hdsx.restful.glzt.structure.fwq.service.FwqServer;
import com.hdsx.restful.glzt.structure.ql.bean.IntValueName;
import com.hdsx.restful.glzt.structure.ql.bean.StatisticalResult;
import com.hdsx.restful.util.Dao;
/**
 * fwqServer实现类
 *
 */
@Service
public class FwqServerImpl extends BaseOpearte<Fwq> implements FwqServer {

	public FwqServerImpl() {
		super("GIS_FWQ");
	}

	@Resource(name="fwqMapper")
	private FwqMapper mapper;

//	@Override
//	public List<Fwq> getList(Map<String, Object> parameter) {
//		return fwqMapper.queryList(parameter);
//	}

	@Override
	public Fwq getById(String id) {
		return mapper.queryOne(id);
	}

	@Override
	public boolean addFwq(Fwq fwq) {
		return mapper.add(fwq)>0;
	}

	@Override
	public boolean updateFwq(Fwq fwq) {
		return mapper.update(fwq)>0;
	}

	@Override
	public boolean deleteById(String id) {
		return mapper.delete(id)>0;
	}

	@Override
	public int queryFwqCountByLxbm(String lxbm) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		return mapper.countByLxbm(parameter);
	}

	@Override
	public List<Fwq> getListByLxbm(String lxbm, int begin, int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("begin", begin);
		parameter.put("end", end);
		return mapper.selectListByLxbm(parameter);
	}

	@Override
	public int queryFwqCountByXzqhbm(String xzqhbm) {
				if(xzqhbm!=null){
					if(xzqhbm.endsWith("0000")){
						xzqhbm=xzqhbm.substring(0,2);
					}else if(xzqhbm.endsWith("00")){
						xzqhbm=xzqhbm.substring(0,4);
					}
				}
				Map<String,Object> parameter=new HashMap<String,Object>();
				parameter.put("xzqhbm", xzqhbm);
				return mapper.countByXzqhbm(parameter);
	}

	@Override
	public List<Fwq> getListByXzqhbm(String xzqhbm, int begin, int end) {
		if(xzqhbm!=null){
			if(xzqhbm.endsWith("0000")){
				xzqhbm=xzqhbm.substring(0,2);
			}else if(xzqhbm.endsWith("00")){
				xzqhbm=xzqhbm.substring(0,4);
			}
		}
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("begin", begin);
		parameter.put("end", end);
		return mapper.selectListByXzqhbm(parameter);
	}

	@Override
	public int queryCount(String lxbm,String xzqhbm,String sxxfx,Double qdzh,Double zdzh,String name) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("sxxfx", sxxfx);
		parameter.put("qdzh", qdzh);
		parameter.put("zdzh", zdzh);
		parameter.put("name", name);
		return mapper.selectCount(parameter);
	}
	@Override
	public List<Fwq> queryList(String lxbm,String xzqhbm,String sxxfx,Double qdzh,Double zdzh,String name,int begin, int end) {
		Map<String,Object> parameter=new HashMap<String,Object>();
		parameter.put("lxbm", lxbm);
		parameter.put("xzqhbm", xzqhbm);
		parameter.put("sxxfx", sxxfx);
		parameter.put("qdzh", qdzh);
		parameter.put("zdzh", zdzh);
		parameter.put("name", name);
		parameter.put("begin", begin);
		parameter.put("end", end);
		List<Fwq> lists=mapper.selectList(parameter);
		return lists;
	}

	@Override
	public Fwq getOne(String fwqbm) {
		return mapper.queryOne(fwqbm);
	}

	@Override
	public  List<Dao> getShapeById(String id) {
		Fwq fwq = mapper.getShapeById(id);
		IGeometry shape=selectShape("ID='"+fwq.getId()+"'");
		fwq.setShape(shape);
		List<Dao> lists=new ArrayList<Dao>();
		lists.add(new Dao("服务区名称",fwq.getFwqmc(),fwq.getPtx(),fwq.getPty()));
		lists.add(new Dao("所在路线",fwq.getLxbm()));
		lists.add(new Dao("路线名称",fwq.getLxmc()));
		lists.add(new Dao("桩号",fwq.getZh()));
		lists.add(new Dao("服务区类型",fwq.getLx()));
		return lists;
	}
	@Override
	public StatisticalResult countByParameter(Map<String,Object> map) {
		List<IntValueName> seriesData = mapper.countTotalByParameter(map);
		List<String> legendData = mapper.selectClassify(map);
		StatisticalResult sr = new StatisticalResult();
		sr.setChartsText("服务区统计");
		sr.setSeriesData(seriesData);
		sr.setLegendData(legendData);
		return sr;
	}
//	@Override
//	public List<Fwq> queryByDbx(String wkt) {
//		List<Fwq> result = new ArrayList<Fwq>();
//		if(wkt == null || wkt.length() == 0){
//			return result;
//		}
//		STRtree tree = SystemCache.getInstance().getFwqTree();
//		Geometry geom = JTSGeometryUtils.WKTToGeometry(wkt);
//		List<Fwq> temp = tree.query(JTS.toEnvelope(geom));
//		if(temp == null || temp.size() == 0)
//			return result;
//		for(Fwq fwq:temp){
//			if(fwq.getShape().intersects(geom)){
//				result.add(fwq);
//			}
//		}
//		return result;
//	}
	 @Override
	   	public List<Znode> fwqNode() {
	   		List<Znode> Node = mapper.node();
	   		return Node;
	   	}
	 @Override
	 public int countTotal(Map<String, Object> map){
		 return mapper.countTotal(map);
	 }
	 
	 @Override
	 public List<Fwq> listAll(String lxbm,String xzqhbm,String sxxfx,Double qdzh,
			Double zdzh,String name) {
		return mapper.listAll(lxbm,xzqhbm,sxxfx,qdzh,zdzh,name);
	 }
	 @Override
	public Fwq queryById(String id) {
			return mapper.selectById(id);
	}
	/**
	 * 分类细节
	 */
	@Override
	public List<Fwq> detail(Map<String, Object> map){
		return mapper.detail(map);
	}
	@Override
	public int countDetail(Map<String, Object> map) {
		return  mapper.countDetail(map);
	}
	@Override
	public List<String> selectName(String name){
		return mapper.selectName(name);
	}
}
